package com.sensePlusVR.utils;

import android.content.Context;
import android.content.res.AssetManager;

import java.io.IOException;


public class LuaUtil {
	
	private static final String fileFolder = "uLua";
	
	
	public static void checkLua(Context context){
		
		String dstFolder = FileUtils.getExternalFilesDir(context);
		
		FileUtils.isFolderExists(dstFolder);
		
		copyFolderOrFile(context,fileFolder,dstFolder);

	}
	
	/**
	 * 拷贝
	 * @param srcPath
	 * @param dstPath
	 */
	private static void copyFolderOrFile(Context context,String assetsDir,String dstDir){
		

		AssetManager assets = context.getAssets();
		
		String[] fileNames = null;
		try {
			 fileNames = assets.list(assetsDir);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if(fileNames==null){
			return;
		}
		
		String dstFilePath = dstDir+"/"+assetsDir;
		
		if(fileNames.length==0){
				
			
			if(FileUtils.isFileExist(dstFilePath)){
				
				FileUtils.deleteFile(dstFilePath);
			}
			
			FileUtils.copyAssetToSDCard(assets, assetsDir, dstFilePath);
			
		}else{
			
			FileUtils.isFolderExists(dstFilePath);
			
			for(String fileName:fileNames){
				
				copyFolderOrFile(context,assetsDir+"/"+fileName,dstDir);	
			}
			
			
		}
	}

}
